package com.wjgl.service;

import java.util.List;

import com.wjgl.dao.FileDAO;
import com.wjgl.domain.File;
import com.wjgl.domain.User;

public class FileService {
	private FileDAO fileDAO;

	public FileDAO getFileDAO() {
		return fileDAO;
	}

	public void setFileDAO(FileDAO fileDAO) {
		this.fileDAO = fileDAO;
	}
	
	public List<File> getAllFiles(){
		return fileDAO.findAll();
	}
	
	public List<File> getAllFilesByUsers(User user){
		return fileDAO.findByProperty("user", user);
	}
	
	public boolean hideFileById(int id){
		boolean b = false;
		File file = fileDAO.findById(id);
		if(file != null){
			file.setIsshared((short)0);
			fileDAO.update(file);
			b=true;
		}
		return b;
	}
	
	public boolean showFileById(int id){
		boolean b = false;
		File file = fileDAO.findById(id);
		if(file != null){
			file.setIsshared((short)1);
			fileDAO.update(file);
			b=true;
		}
		return b;
	}
	
	public boolean deleteFileById(int id){
		boolean b = false;
		File file = fileDAO.findById(id);
		if(file != null){
			fileDAO.delete(file);
			b=true;
		}
		return b;
	}
}
